/*
 * Copyright (c) 2023-2025 110476592@qq.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/**
 * @file draw_toolbar.cpp
 * @brief 截图工具 
 * @author 110476592@qq.com 
 * @note   承接Qt项目外包定制开发。长期接收C++项目实训学徒,联系QQ：110476592。
 */

 
#include <common/global.h>
#include "draw_toolbar.h"
#include <QToolButton>
#include <QAction>

DrawToolBar::DrawToolBar(QWidget *parent)
    : AbsFloatToolBar{parent}
{
    setObjectName("DrawToolBar");
    setStyleSheet(
        "DrawToolBar{padding:10px;background-color:rgba(120, "
        "120, 120,240);border-bottom-left-radius:4px;border-bottom-right-radius:4px;}");
}

void DrawToolBar::initButtons()
{
    QToolButton *btn = addToolButton(tr("移动"),(int)IconFont::FA_MOVE,CommandType::CMD_MOVE_TOOL_BAR);
    m_buttonGroup->addButton(btn);
    m_hLayout->addWidget(btn);

    QString style = QString::fromUtf8(
        "QToolButton{padding:2px; color:#666;border: 0px solid #C84A46; }"
        "QToolButton:hover {"
        "border-radius:2px;"
        "}");

    btn->setStyleSheet(style);

    btn = addToolButton(tr("画笔"),(int)IconFont::FA_PEN,CommandType::CMD_PEN);
    m_buttonGroup->addButton(btn);
    m_hLayout->addWidget(btn);

    btn = addToolButton(tr("形状"),(int)IconFont::FA_SHAP,CommandType::CMD_SHAP);
    m_buttonGroup->addButton(btn);
    m_hLayout->addWidget(btn);
    btn = addToolButton(tr("撤销"),(int)IconFont::FA_UNDO,CommandType::CMD_UNDO);
    m_buttonGroup->addButton(btn);
    m_hLayout->addWidget(btn);

    btn = addToolButton(tr("重做"),(int)IconFont::FA_REDO,CommandType::CMD_REDO);
    m_buttonGroup->addButton(btn);
    m_hLayout->addWidget(btn);

    btn = addToolButton(tr("清除"),(int)IconFont::FA_RUBBER,CommandType::CMD_CLEAN);
    m_buttonGroup->addButton(btn);
    m_hLayout->addWidget(btn);

    btn = addToolButton(tr("剪切板"),(int)IconFont::FA_CLIPBOARD,CommandType::CMD_CLIPBOARD);
    m_buttonGroup->addButton(btn);
    m_hLayout->addWidget(btn);

    btn = addToolButton(tr("保存文件"),(int)IconFont::FA_SAVE,CommandType::CMD_SAVE);
                                           m_buttonGroup->addButton(btn);
                           m_hLayout->addWidget(btn);

    QSize newPreferredSize = preferredSize();
    resize(newPreferredSize.width(), newPreferredSize.height());
}

void DrawToolBar::updatePosition(const QRect &parentRect, const QRect &selectionRect)
{
    Q_UNUSED(selectionRect);

    if(parentRect.isEmpty())
    {
        return ;
    }

    int top = parentRect.top();
    QRect rc = this->rect();
    QPoint pt((parentRect.width() - rc.width()) / 2, top);


    move(pt);
}
